package com.bw.cashier.page

import android.os.Bundle
import android.util.Log
import androidx.activity.enableEdgeToEdge
import androidx.activity.viewModels
import androidx.appcompat.app.AppCompatActivity
import androidx.core.view.ViewCompat
import androidx.core.view.WindowInsetsCompat
import com.alibaba.android.arouter.facade.annotation.Autowired
import com.alibaba.android.arouter.facade.annotation.Route
import com.alibaba.android.arouter.launcher.ARouter
import com.blankj.utilcode.util.SPUtils
import com.blankj.utilcode.util.ToastUtils
import com.bw.base.path.RouterPath
import com.bw.cashier.R
import com.bw.cashier.databinding.ActivityChargeDetailBinding
import com.bw.cashier.vm.CashierViewModel
import com.bw.common.view.BaseMvvmActivity
import dagger.hilt.android.AndroidEntryPoint

/**
 * 缴费详情
 */
@Route(path = RouterPath.PATH_CHARGE_DETAIL_PATH)
@AndroidEntryPoint
class ChargeDetailActivity : BaseMvvmActivity<ActivityChargeDetailBinding>() {

    private val mViewModel: CashierViewModel by viewModels()
    override fun getLayoutId(): Int = R.layout.activity_charge_detail
    val sid = SPUtils.getInstance().getString("sid")
    override fun initViews() {
        super.initViews()

        ToastUtils.showLong("${sid}")
        Log.d("--sid","${sid}")
        mDataBinding.back.setOnClickListener { finish() }
    }


    override fun loadData() {
        super.loadData()
        mViewModel.getChargeDetail(sid.toInt())
    }


    override fun observeDataChanged() {
        super.observeDataChanged()
        mViewModel.mChargeDetailSuccess.observe( this){
            mDataBinding.address.text = it.chargeType
            mDataBinding.code.text = "交易流水号:${removeSymbols(it.paymentTime)+it.contactNumber}"
            mDataBinding.feePeriodValue.text = it.effectiveDate+"至"+it.expirationDate
            mDataBinding.unitPriceValue.text = "￥${it.chargeAmount}"
            mDataBinding.quantityValue.text = "1"
            mDataBinding.receivableAmountValue.text = "￥${it.receivableAmount}"
            mDataBinding.discountAmountValue.text = "￥${it.discountAmount}"
            mDataBinding.penaltyAmountValue.text = "￥${it.penalty}"
            mDataBinding.payableAmountValue.text = "￥${it.actualAmount}"
            mDataBinding.totalReceivableValue.text = "￥${it.receivableAmount}"
            mDataBinding.totalDiscountValue.text = "￥${it.discountAmount}"
            mDataBinding.totalPayableValue.text = "￥${it.actualAmount}"
            mDataBinding.totalPayableValue.text = "￥${it.actualAmount}"
            mDataBinding.balanceDeductionValue.text = "￥${it.balanceDeduction}"
            mDataBinding.actualTotalValue.text = "￥${it.actualAmount}"
            mDataBinding.paymentMethodValue.text = it.paymentMethod
            mDataBinding.paymentTimeValue.text = it.paymentTime
            mDataBinding.operatorValue.text = it.payerName
        }
    }

    fun removeSymbols(dateTime: String): String {
        return dateTime.replace("[-: ]".toRegex(), "")
    }
}